﻿<%@ Page Language="C#" AutoEventWireup="true"  Inherits="ZX.Web.UI.Controls.BasePage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
 <title></title>
    <link href="/Scripts/JQuery_zTree_v3.3/css/zTreeStyle/zTreeStyle.css" rel="stylesheet"  type="text/css" />
    <link href="/Scripts/JQuery_zTree_v3.3/css/demo.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
    .yui-skin-sam table {
	  width: 100%; 
    }
    
    input[type=text]
    {
        height:15px;
        line-height:16px;
        font-size:12px;
    }
    input[type=button]
    {
        height:15px;
        line-height:16px;
        font-size:12px;
    }
    .headcol {
        position:relative;
        /*width:5em;*/
        left:0;
        top:auto;
        border-right: 0px none black;
        border-top-width:3px; /*only relevant for first row*/
        margin-top:-3px; /*compensate for top border*/
    }
    #button-example-form fieldset, 
    #button-example-form fieldset div {
        border: 2px groove #ccc;
        margin: .5em;
        padding: .5em;
    }
    .yui-layout-unit-bottom 
    {
       border:0px;
    }
    
    #yui-gen6
    {
        border:0px;
    }

</style>
</head>
<body class="yui-skin-sam">
    <form id="form1" runat="server">
    <!-- 左栏 -->
    <div id="leftPanel">
         <ul class='ztree' id='TreeData' style="width: 100%; height: 100%; border: 0px; margin: -5px;">
        </ul>
    </div>
    
    </form>
</body>
 <script>
    var _currentUserID = '<%=User.UserID %>',
        _currentUserName = '<%=User.UName %>';
    var _currentUser = <% =UserJson %>;
    var _currentEmloyeeInfo=<%=EmployeeInfo %>;

</script>   
    <script src="/Scripts/jquery-1.6.min.js" type="text/javascript"></script>

    <script src="/Scripts/JQuery_zTree_v3.3/js/jquery.ztree.core-3.3.js" type="text/javascript"></script>
    <script src="/Scripts/JQuery_zTree_v3.3/js/jquery.ztree.excheck-3.3.js" type="text/javascript"></script>
    <script src="/Scripts/JQuery_zTree_v3.3/js/jquery.ztree.exedit-3.3.js" type="text/javascript"></script>
    <script src="/Scripts/Jquery.form.js" type="text/javascript"></script>
     <script src="/Scripts/Jquery.action.js" type="text/javascript"></script>
<script type="text/javascript">
    /* 树 */
    var setting = {
        edit: {
            drag: {
                autoExpandTrigger: true,
                prev: dropPrev,
                inner: dropInner,
                next: dropNext
            },
            enable: true,
            showRemoveBtn: false,
            showRenameBtn: false,
            editNameSelectAll: false

        },
        data: {
            key: {
                title: "t"
            },
            simpleData: {
                enable: true
            }
        },
        callback: {
            beforeClick: beforeClick,
            onClick: onClick,
            beforeDrag: beforeDrag,
            beforeDrop: beforeDrop,
            beforeDragOpen: beforeDragOpen,
            onDrag: onDrag,
            onDrop: onDrop,
            onExpand: onExpand
        }
    };


    var DutyInfosetting = {
        edit: {
            enable: true,
            showRemoveBtn: false,
            showRenameBtn: false
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        callback: {
            beforeDrag: beforeDrag,
            beforeDrop: beforeDrop
        }
    };

    var log, className = "dark";
    function beforeClick(treeId, treeNode, clickFlag) {
        className = (className === "dark" ? "" : "dark");
        return (treeNode.click != false);
    }

    var _treeNode = null;
    function onClick(event, treeId, treeNode, clickFlag) {
        //debugger
        _treeNode = treeNode;
        //$("#" + defaults.CtrolID).val(treeNode.name);
        //debugger
        if (treeNode.IsLoaded == 'true') {
            return;
        }
        //else if (treeNode.flag == '1d') {
        treeNode.IsLoaded = "true";
        getUserData();
        //}
        //setValue(treeNode.id);
        //hide();
    }

    _Data = null;
    function getUserData() {
        var deptID = _treeNode.id;
        $.get("/Extend/AjaxData/DataTableJsonList.aspx?entity=V_UserData&type=0&condition=DeptID='" + deptID + "'",
            function (d, t) {
                //debugger
                if (d == '{"total":0,"rows":}') {
                    return;
                }
                var data = eval("(" + d + ")");
                var temp = [];
                $.each(data.rows, function (e) {
                    //debugger
                    AddNewNode(data.rows[e].ID, data.rows[e].CName, data.rows[e].PostName);
                });
            });
    }


    function AddNewNode(id, name, postName) {
        var zTree = $.fn.zTree.getZTreeObj("TreeData");
        //debugger
        zTree.addNodes(_treeNode, { id: id, pId: _treeNode.id, name: name + "(" + postName + ")", nodetype: "3e", checked: true, icon: "/images/b.png" });
        var nodes = zTree.getNodes();
        $.each(nodes, function (i) {
            //debugger
            nodes[i].nocheck = true;
            zTree.updateNode(nodes[i]);

        });
    }
    function addHoverDom(treeId, treeNode) {

    };
    function beforeDragOpen(treeId, treeNode) {
    }

    function beforeDrag(treeId, treeNodes) {
    }
    function beforeDrop(treeId, treeNodes, targetNode, moveType) {
    }

    function dropPrev(treeId, nodes, targetNode) {
    }
    function dropInner(treeId, nodes, targetNode) {

    }
    function dropNext(treeId, nodes, targetNode) {
    }

    function onDrag(event, treeId, treeNodes) {
    }
    function onDrop(event, treeId, treeNodes, targetNode, moveType, isCopy) {
    }
    function onExpand(event, treeId, treeNode) {
    }

    function callback(data) {
        var _temp = [];
        $.each(data, function (e) {
            _temp.push($.extend(data[e], { drag: true }));
        }
        );
        $.fn.zTree.init($("#TreeData"), setting, _temp);
        return;
    };

    function getUrl() {
        //debugger
        switch (getPar1("type")) {
            case "menuRight":
                return "/Extend/AjaxData/jsonlist.aspx?action=GetUserRight";
            case "selfDeptData":
                return "/Extend/AjaxData/jsonlist.aspx?action=GetUserDeptData";
            case "menuData":
                return "/Extend/AjaxData/DataTableJsonList.aspx?r=" + Math.random() + "&entity=v_sysmenu&type=0";
            case "deptData":
                return "/Extend/AjaxData/DataTableJsonList.aspx?r=" + Math.random() + "&entity=v_dept&type=0";
            default:
                return "/Extend/AjaxData/DataTableJsonList.aspx?r=" + Math.random() + "&entity=v_sysmenu&type=0";
        }
    }

    function InitLeftData() {
        if (getPar1("type") == "selfDeptData") {
            //debugger
            var data = fnRunProc2("Usp_GetSelfDepts", _currentUserID, callback);
            return;
        }
        $.get(getUrl(),
            function (d, t) {
                //debugger
                var data = eval("(" + d + ")");
                var _temp = [];
                if (getPar1("type") == "menuRight") {
                    $.each(data, function (e) {
                            _temp.push($.extend(data[e], { drag: true }));
                        }
                );
                }else{
                    $.each(data.rows, function (e) {
                            _temp.push($.extend(data.rows[e], { drag: true }));
                        }
                    );
                }
                $.fn.zTree.init($("#TreeData"), setting, _temp);
            });
    }

    function fnResize() {
        $("#data").height($(window).height());
    }
    InitLeftData();
    function Save() {
        var sItems = $.fn.zTree.getZTreeObj("TreeData").getSelectedNodes();
        var _v = "";
        var _t = "";
        $.each(sItems, function (i) {
            _v = (_v == "") ? sItems[i].id : (_v + "@" + sItems[i].id);
            _t = (_t == "") ? sItems[i].name.split("(")[0] : (_t + "@" + sItems[i].name.split("(")[0]);
        });
        if (getPar1("t") == "") {
            if (typeof (parent._fnCallBack) == "function") {
                parent._fnCallBack(_v);
            }
        } else {
            if (typeof (parent._fnGetPersonCustomerInfoCallBack) == "function") {
                parent._fnGetPersonCustomerInfoCallBack(_v);
            }

        }
       
    }
</script> 
</html>
